package com.bodu.depress.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.depress.entity.request.DepressCollectTypeRequest;
import com.bodu.depress.entity.vo.DepressCollectTypeVo;
import com.bodu.depress.service.DepressCollectTypeService;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 题集 API
* @author Administrator
*/
@Api(tags = "题集 API")
@RestController
@RequestMapping("/depressCollectType")
public class DepressCollectTypeController extends AbstractCommonController<DepressCollectTypeService, DepressCollectTypeRequest, DepressCollectTypeVo> {

    private final DepressCollectTypeService depressCollectTypeService;

    public DepressCollectTypeController(DepressCollectTypeService depressCollectTypeService) {
        this.depressCollectTypeService = depressCollectTypeService;
    }

    @TraceLog()
    @GetMapping("{id}")
    public Result<DepressCollectTypeVo> getModel(@PathVariable("id") Long id) {
        return super.getModel(depressCollectTypeService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存题集")
    public Result<Integer> save(@RequestBody DepressCollectTypeRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(depressCollectTypeService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新题集")
    public Result<Integer> update(@RequestBody DepressCollectTypeRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(depressCollectTypeService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("题集-查询")
    public Result<List<DepressCollectTypeVo>>listPage(@RequestBody ParamReq<DepressCollectTypeRequest> req) {
        return super.listPage(depressCollectTypeService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("题集-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<DepressCollectTypeRequest> req) {
        return super.countPage(depressCollectTypeService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("题集-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<DepressCollectTypeRequest> req) {
        return super.page(depressCollectTypeService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除题集")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(depressCollectTypeService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除题集")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(depressCollectTypeService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
